const formatDate = (dateStr, fmt = "yyyy-MM-dd hh:mm:ss") => {
  if (!dateStr) return "";
  let date = new Date(dateStr);
  let o = {
    "y+": date.getFullYear(),
    "M+": date.getMonth() + 1,
    "d+": date.getDate(),
    "h+": date.getHours(),
    "m+": date.getMinutes(),
    "s+": date.getSeconds(),
  };
  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      const str = o[k] + "";
      fmt = fmt.replace(RegExp.$1, str.length > 1 ? str : padLeftZero(str));
    }
  }
  return fmt;
};
console.log(formatDate("2021-10-11 14:37:40", "yyyy:MM:dd hh-mm-ss"));
